package com.icode.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: my_code
 * @Email: my_code@foxmail.com
 * @Create: 2020-12-14 18:20
 */
public class CASDemo {

    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(1024);

        //public final boolean compareAndSet(int expect, int update)
        //如果是期望的值，那么就更新，否则不做处理
        atomicInteger.compareAndSet(1024, 2048);
        System.out.println(atomicInteger);
        atomicInteger.compareAndSet(2040, 4096);
        System.out.println(atomicInteger);

    }
}
